USE F90_UNIX_ENV
This module contains part of a Fortran API to functions detailed in ISO/IEC 9945-1:1990 Portable Operating System Interface (POSIX) - Part 1: System Application Program Interface (API) [C Language].
The functions in this module are from Section 4: Process Environment, plus gethostname from 4.3BSD.
Error handling is described in F90_UNIX_ERRNO. Note that for procedures with an optional ERRNO argument, if an error occurs and ERRNO is not present, the program will be terminated.
INTEGER,PARAMETER :: CLOCK_TICK_KINDThe integer kind used for clock ticks (see TIMES).
INTEGER,PARAMETER :: LONG_KINDThe integer kind corresponding to the C type "long". This is used for the type of one of the arguments of SYSCONF.
INTEGER,PARAMETER :: SC_STDIN_UNIT, SC_STDOUT_UNIT, SC_STDERR_UNIT, SC_ARG_MAX, SC_CHILD_MAX, SC_CLK_TCK, SC_JOB_CONTROL, SC_OPEN_MAX, SC_NGROUPS_MAX, SC_SAVED_IDS, SC_STREAM_MAX, SC_TZNAME_MAX, SC_VERSIONValues used as arguments to SYSCONF. The following table describes the returned information from SYSCONF, this is not the value of the SC_* constant.
INTEGER,PARAMETER :: TIME_KINDThe integer kind used for holding date/time values (see TIME).
TYPE TMS INTEGER(CLOCK_TICK_KIND) UTIME, STIME, CUTIME, CSTIME END TYPEDerived type holding CPU usage time in clock ticks. UTIME and STIME contain CPU time information for a process, CUTIME and CSTIME contain CPU time information for its terminated child processes. In each case this is divided into user time (UTIME, CUTIME) and system time (STIME, CSTIME).
TYPE UTSNAME CHARACTER*(...) SYSNAME, NODENAME, RELEASE, VERSION, MACHINE END TYPEDerived type holding data returned by UNAME. Note that the character length of each component is fixed, but may be different on different systems. The values in these components are blank-padded (if short) or truncated (if long). For further information see ISO/IEC 9945-1:1990.
PURE INTEGER (KIND=CLOCK_TICK_KIND) FUNCTION CLK_TCK()Returns the number of clock ticks in one second of CPU time (see TIMES).
PURE SUBROUTINE CTERMID(S,LENS) CHARACTER*(*),OPTIONAL,INTENT(OUT) :: S INTEGER,OPTIONAL,INTENT(OUT) :: LENSIf present, LENS is set to the length of the filename of the controlling terminal. If present, S is set to the filename of the controlling terminal. If S is longer than the filename of the controlling terminal it is padded with blanks; if S is shorter it is truncated - it is the user's responsibility to check the value of LENS to detect such truncation.
If the filename of the controlling terminal cannot be determined for any reason LENS (if present) will be set to zero and S (if present) will be blank.
SUBROUTINE GETARG(K,ARG,LENARG,ERRNO) INTEGER,INTENT(IN) :: K CHARACTER*(*),OPTIONAL,INTENT(OUT) :: ARG INTEGER,OPTIONAL,INTENT(OUT) :: LENARG, ERRNOAccesses command-line argument number K, where argument zero is the program name. If ARG is present, it receives the argument text (blank-padded or truncated as appropriate if the length of the argument differs from that of ARG). If LENARG is present, it receives the length of the argument. If ERRNO is present, it receives the error status.
Note that if K is less than zero or greater than the number of arguments (returned by IARGC) error EINVAL (see F90_UNIX_ERRNO) is raised.
PURE INTEGER FUNCTION GETEGID()Returns the effective group number of the calling process.
SUBROUTINE GETENV(NAME,VALUE,LENVALUE,ERRNO) CHARACTER*(*),INTENT(IN) :: NAME CHARACTER*(*),OPTIONAL,INTENT(OUT) :: VALUE INTEGER,OPTIONAL,INTENT(OUT) :: LENVALUE, ERRNOAccesses the environment variable named by NAME. If VALUE is present, it receives the text value of the variable (blank-padded or truncated as appropriate if the length of the value differs from that of VALUE). If LENVALUE is present, it receives the length of the value. If ERRNO is present, it receives the error status.
If there is no such variable, error EINVAL (see F90_UNIX_ERRNO) is raised. Other possible errors include ENOMEM.
PURE INTEGER FUNCTION GETEUID()Returns the effective user number of the calling process.
PURE INTEGER FUNCTION GETGID()Returns the group number of the calling process.
SUBROUTINE GETGROUPS(GROUPLIST,NGROUPS,ERRNO) INTEGER,OPTIONAL,INTENT(OUT) :: GROUPLIST(:), NGROUPS, ERRNORetrieves supplementary group number information for the calling process. If GROUPLIST is present, it is filled with the supplementary group numbers. If NGROUPS is present, it receives the number of supplementary group numbers. If ERRNO is present, it receives the error status.
If GROUPLIST is too small to contain the complete list of supplementary group numbers, error EINVAL (see F90_UNIX_ERRNO) is raised. The maximum number of supplementary group numbers can be found using SYSCONF (enquiry SC_NGROUPS_MAX); alternatively, CALL GETGROUPS(NGROUPS=N) will reliably return the actual number in use.
PURE SUBROUTINE GETHOSTNAME(NAME,LENNAME) CHARACTER*(*),OPTIONAL,INTENT(OUT) :: NAME INTEGER,OPTIONAL,INTENT(OUT) :: LENNAMEThis provides the functionality of 4.3BSD's gethostname. If NAME is present it receives the text of the standard host name for the current processor, blank-padded or truncated if appropriate. If LENNAME is present it receives the length of the host name. If no host name is available LENNAME will be zero.
PURE SUBROUTINE GETLOGIN(S,LENS) CHARACTER*(*),OPTIONAL,INTENT(OUT) :: S INTEGER,OPTIONAL,INTENT(OUT) :: LENSAccesses the user name (login name) associated with the calling process. If S is present, it receives the text of the name (blank-padded or truncated as appropriate if the length of the login name differs from that of S). If LENS is present, it receives the length of the login name.
PURE INTEGER FUNCTION GETPGRP()Returns the process group number of the calling process.
PURE INTEGER FUNCTION GETPID()Returns the process number of the calling process.
PURE INTEGER FUNCTION GETPPID()Returns the process number of the parent of the calling process.
PURE INTEGER FUNCTION GETUID()Returns the user number of the calling process.
PURE INTEGER FUNCTION IARGC()Returns the number of command-line arguments. This will be -1 if even the program name is unavailable.
SUBROUTINE ISATTY(LUNIT,ANSWER,ERRNO) INTEGER,INTENT(IN) :: LUNIT LOGICAL,INTENT(OUT) :: ANSWER INTEGER,OPTIONAL,INTENT(OUT) :: ERRNOANSWER receives the value .TRUE. if and only if logical unit LUNIT is connected to a terminal.
If LUNIT is not a valid unit number or is not connected to any file, error EBADF (see F90_UNIX_ERRNO) is raised.
SUBROUTINE SETGID(GID,ERRNO) INTEGER,INTENT(IN) :: GID INTEGER,OPTIONAL,INTENT(OUT) :: ERRNOSets the group number of the calling process to GID. For full details refer to section 4.2.2 of ISO/IEC 9945-1:1990.
If GID is not a valid group number, error EINVAL (see F90_UNIX_ERRNO) is raised. If the process is not allowed to set the group number to GID, error EPERM is raised.
SUBROUTINE SETPGID(PID,PGID,ERRNO) INTEGER,INTENT(IN) :: PID, PGID INTEGER,OPTIONAL,INTENT(OUT) :: ERRNOSets the process group number of process PID (or, if PID is zero, the calling process) to PGID. For full details refer to section 4.3.3 of ISO/IEC 9945-1:1990.
Possible errors include EACCES, EINVAL, ENOSYS, EPERM, ESRCH (see F90_UNIX_ERRNO).
SUBROUTINE SETSID(SID,ERRNO) INTEGER,INTENT(IN) :: SID INTEGER,OPTIONAL,INTENT(OUT) :: ERRNOCreates a session and sets the process group number of the calling process. For full details refer to section 4.3.2 of ISO/IEC 9945-1:1990.
Possible errors include EPERM (see F90_UNIX_ERRNO).
SUBROUTINE SETUID(UID,ERRNO) INTEGER,INTENT(IN) :: UID INTEGER,OPTIONAL,INTENT(OUT) :: ERRNOSets the user number of the calling process to UID. For full details refer to section 4.2.2 of ISO/IEC 9945-1:1990.
If UID is not a valid group number, error EINVAL (see F90_UNIX_ERRNO) is raised. If the process is not allowed to set the user number to UID, error EPERM is raised.
SUBROUTINE SYSCONF(NAME,VAL,ERRNO) INTEGER,INTENT(IN) :: NAME INTEGER(LONG_KIND),INTENT(OUT) :: VAL INTEGER,OPTIONAL,INTENT(OUT) :: ERRNOReturns the value of a system configuration variable. The variables are named by integer PARAMETERs defined in this module, and are described in the PARAMETER DESCRIPTION section.
If NAME is not a valid configuration variable name, error EINVAL (see F90_UNIX_ERRNO) is raised.
SUBROUTINE TIME(ITIME,ERRNO) INTEGER(TIME_KIND),INTENT(OUT) :: ITIME INTEGER,OPTIONAL,INTENT(OUT) :: ERRNOITIME receives the operating system date/time in seconds since the Epoch.
INTEGER(KIND=CLOCK_TICK_KIND) FUNCTION TIMES(BUFFER) TYPE(TMS),INTENT(OUT) :: BUFFERThis function returns the elapsed real time in clock ticks since an arbitrary point in the past, or -1 if the function is unavailable. BUFFER is filled in with CPU time information for the calling process and any terminated child processes.
If this function returns zero the values in BUFFER will still be correct but the elapsed-time timer was not available.
SUBROUTINE TTYNAME(LUNIT,S,LENS,ERRNO) INTEGER,INTENT(IN) :: LUNIT CHARACTER*(*),OPTIONAL,INTENT(OUT) :: S INTEGER,OPTIONAL,INTENT(OUT) :: LENS, ERRNOAccesses the name of the terminal connected to logical unit LUNIT. If S is present, it receives the text of the terminal name (blank-padded or truncated as appropriate, if the length of the terminal name differs from that of S). If LENS is present, it receives the length of the terminal name. If ERRNO is present, it receives the error status.
If LUNIT is not a valid logical unit number, or is not connected, error EBADF (see F90_UNIX_ERRNO) is raised.
SUBROUTINE UNAME(NAME,ERRNO) TYPE(UTSNAME),INTENT(OUT) :: NAME INTEGER,OPTIONAL,INTENT(OUT) :: ERRNOReturns information about the operating system in NAME.
f90_unix_errno(3), f95(1), intro(3), nag_modules(3).
Please report any bugs found to "support@nag.co.uk" or "infodesk@nag.com", along with any suggestions for improvements.